var imgbase64='';
function onFileChange(e) {
        var that = this;
        var fileObj = document.getElementById("imgLoad").files;
        var preView = document.getElementById("preView");
                     
        for(var i=0;i<fileObj.length;i++){
            var img = fileObj[i];
              photoCompress(img, {
                      width:200,
                      height:200,
                      quality: 0.8
                  }, function(base64Codes){
                  	document.getElementById("Filetext").innerHTML = "认证资料已上传";
                   imgbase64 = base64Codes;
                      
                  });
           
        }  
            
               
        }
        function photoCompress(file,w,callback){
          var that = this;
            var ready=new FileReader();
                ready.readAsDataURL(file);
                ready.onload=function(){
                    var re=this.result;
                    canvasDataURL(re,w,callback)
                }
        }
        function canvasDataURL(path, obj, callback){
             var img = new Image();
             img.src = path;
             img.onload = function(){
              var that = this;
              // 默认按比例压缩
              var w = that.width,
               h = that.height,
               scale = w / h;
               w = obj.width || w;
               h = obj.height || (w / scale);
              var quality = 0.5;  // 默认图片质量为0.5
              //生成canvas
              var canvas = document.createElement('canvas');
              var ctx = canvas.getContext('2d');
              // 创建属性节点
              var anw = document.createAttribute("width");
              anw.nodeValue = w;
              var anh = document.createAttribute("height");
              anh.nodeValue = h;
              canvas.setAttributeNode(anw);
              canvas.setAttributeNode(anh); 
              ctx.drawImage(that, 0, 0, w, h);
              // 图像质量
              if(obj.quality && obj.quality <= 1 && obj.quality > 0){
               quality = obj.quality;
              }
              // quality值越小，所绘制出的图像越模糊
              var base64 = canvas.toDataURL('image/jpeg', quality);
              // 回调函数返回base64的值
              callback(base64);
            }
        }